package src.mian.java;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import java.io.IOException;

public class HDFSDeleteDirectoryExample {
    public static void main(String[] args) {
        String hdfsUri = "hdfs://192.168.254.100:8020";
        String directoryPath = "/car";
        Configuration conf = new Configuration();
        conf.set("fs.defaultFS", hdfsUri);
        try {
            FileSystem fs = FileSystem.get(conf);
            Path path = new Path(directoryPath);

            // Check if the directory exists
            if (fs.exists(path)) {
                // Delete the directory recursively
                fs.delete(path, true);
                System.out.println("Directory deleted successfully");
            } else {
                System.out.println("Directory does not exist");
            }

            // Close the file system
            fs.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
